package com.xxcxcxcx.jobsystem.common.command.argumets;

import com.google.gson.JsonObject;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import com.xxcxcxcx.jobsystem.common.JobsClass;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.SharedSuggestionProvider;
import net.minecraft.commands.arguments.EntityArgument;
import net.minecraft.commands.synchronization.ArgumentSerializer;
import net.minecraft.network.FriendlyByteBuf;

import java.util.Arrays;
import java.util.Collection;
import java.util.concurrent.CompletableFuture;

public class JobArgument implements ArgumentType<String> {
    private static final Collection<String> EXAMPLES = Arrays.asList(JobsClass.Farmer);

    protected JobArgument() {

    }

    @Override
    public String parse(StringReader reader) throws CommandSyntaxException {
        String str = reader.readString();
        if(JobsClass.isJob(str)) {
            return str;
        } else {
            throw new IllegalArgumentException("Argument is not an existing job");
        }
    }

    @Override
    public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
        return SharedSuggestionProvider.suggest(JobsClass.Jobs, builder);
    }

    @Override
    public Collection<String> getExamples() {
        return EXAMPLES;
    }

    public static String getJob(CommandContext<CommandSourceStack> pContext, String pName) throws CommandSyntaxException {
        return pContext.getArgument(pName, String.class);
    }

    public static JobArgument job() {
        return new JobArgument();
    }
}
